<template>
  <div class="dom-to-img">
    <h1>莫到前路艰难，自有神明相助</h1>
    <el-button @click="screenshot">下载 h1 标签·</el-button>
  </div>
</template>

<script>
import html2canvas from 'html2canvas'
export default {
  methods: {
    async screenshot() {
      const dom = document.querySelector('h1')
      const res = await html2canvas(dom)
      const link = document.createElement('a')
      link.href = res.toDataURL()
      link.setAttribute('download', 'h1标签')
      document.body.appendChild(link)
      link.click()
      document.body.removeChild(link)
    }
  }
}
</script>

<style scoped lang="scss">

</style>